package org.example.teaView;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

public class DeleteTopicView extends JFrame implements Runnable{
    HandleDeleteTopic handleDeleteTopic;
    JButton back,delete;
    JTextField inputID,hintMess;
    public DeleteTopicView(){
        init();
        DeleteTopicListener();
    }

    private void init() {
        this.setSize(512,512);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
        this.setAlwaysOnTop(true);
        this.setLayout(null);
        this.setVisible(true);
        this.setTitle("删除题目页面-3220608045吉治霖软件2202");

        //ID:  设置
        Font font = new Font(null,1,16);
        JLabel IDText = new JLabel("题目序号：");
        IDText.setFont(font);
        IDText.setBounds(100,35,110,22);
        this.getContentPane().add(IDText);

        inputID = new JTextField();
        inputID.setBounds(190,35,150,22);
        this.getContentPane().add(inputID);

        // 删除题库按钮 设置
        delete = new JButton("删除");
        delete.setBounds(130,350,80,30);
        this.getContentPane().add(delete);
        // 返回题库按钮 设置
        back = new JButton("返回");
        back.setBounds(230,350,80,30);
        this.getContentPane().add(back);
        //提示框
        hintMess = new JTextField(20);
        hintMess.setEditable(false);
        hintMess.setBounds(50,400,380,30);
        this.getContentPane().add(hintMess);
    }

    private void DeleteTopicListener() {
        handleDeleteTopic = new HandleDeleteTopic();// HandleAddWord
        handleDeleteTopic.setDeleteTopicView(this);
        delete.addActionListener(handleDeleteTopic);
        back.addActionListener(handleDeleteTopic);
    }

    @Override
    public void run() {
        String str = null;
        while (true){
            try {
                str = handleDeleteTopic.in.readUTF();
                hintMess.setText(str.substring(4));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
